package com.autotest.nore.service;

import com.autotest.nore.mapper.EnvironmentParamMapper;
import com.autotest.nore.dto.EnvironmentParamDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class EnvironmentParamService {

    @Autowired
    EnvironmentParamMapper environmentParamMapper;

    public void add(EnvironmentParamDTO envParam) {
        envParam.setId(UUID.randomUUID().toString());
        environmentParamMapper.add(envParam);
    }
    public void update(EnvironmentParamDTO envParam) {
        environmentParamMapper.update(envParam);
    }

    public void delete(String id) {
        environmentParamMapper.delete(id);
    }

    public List<EnvironmentParamDTO> getList(String projectId,String environment) {
        if(environment==null|| environment.trim().isEmpty()){
            return environmentParamMapper.getList(projectId.trim());
        }else if(environment.trim().equals("common")){
            return environmentParamMapper.getListCommon();
        }else{
            Map<String,String> proEnv=new HashMap<>();
            proEnv.put("environmentName",environment.trim());
            proEnv.put("projectId",projectId.trim());
            return environmentParamMapper.getListEnv(proEnv);
        }
    }


}
